package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyDemo2 {
    public static void main(String[] args) throws IOException {
        long start=System.currentTimeMillis();
        FileInputStream fis=new FileInputStream("yy.jpg");
        FileOutputStream fos=new FileOutputStream("dzy2.jpg");
        byte[] b=new byte[1024*10];//10kb

        int len;//记录每次实际读取的字节数
        while ((len=fis.read(b))!=-1){//每次读取10kb并判断是否到末尾
            fos.write(b,0,len);
            //将字节数组b从0开始连续len个字节写出(读多少写多少)
        }

        long end=System.currentTimeMillis();
        System.out.println("复制完毕!耗时:"+(end-start)+"ms");
        fis.close();
        fos.close();


        /*
        long start=System.currentTimeMillis();
        FileInputStream fis=new FileInputStream("yy.jpg");
        FileOutputStream fos=new FileOutputStream("dzy2.jpg");
        byte[] b=new byte[1024*10];//10kb
        while (fis.read(b)!=-1){
            fos.write(b);
        }
        long end=System.currentTimeMillis();
        System.out.println("复制完毕!耗时:"+(end-start)+"ms");
        fis.close();
        fos.close();
        */
    }
}
